<html>
<head>
<#include "common/common.html"/>
<meta charset="UTF-8">
<#include "common/css_js.html"/> <#include "common/fupage.html" />
<#include "common/artdialog.html"/>
<script type="text/javascript">
	$(document).ready(function() {
		var backUrl = base + "/role/";
		$("#add").bind("click", function() {
			var pass = $("#addForm").validationEngine("validate");
			if(!pass){
				return;
			}
			var name = $("#name").val();
			var remark = $("#remark").val();
			var privilegeStr = "";
			$("input[name='privilegeStr']:checked").each(function(i, str) {
				console.log(i + "," + $(this).val());
				privilegeStr += $(this).val() + ",";
			});
			post(base + "/role/doadd.js?v=${bv}on", {
				"name" : name,
				"remark" : remark,
				"privilegeStr" : privilegeStr
			}, function(data) {
				if (data.code == 1) {
					var d = dialog({
						title : defaultAlertTitle,
						content : '添加角色成功',
						cancel : false,
						ok : function() {
							load(backUrl);
						}
					});
					d.show();
				}
			});
		});

		cancelBind(backUrl);
	});
</script>
</head>
<body>
	<div>
		<form id="addForm" class="validationEngine">
			<table>
				<tr>
					<td>角色名:</td>
					<td><input type="text" name="name" id="name" maxlength="20" class="validate[required]">
					</input></td>
				</tr>
				<tr>
					<td>备注:</td>
					<td><input type="text" name="remark" id="remark"></input></td>
				</tr>

				<#list privilegeList as item> <#if (item_index+1)%4 ==1>
				<tr>
					<td>${item.name}<input type="checkbox" name="privilegeStr"
						value="${item.acl}" />&nbsp;
					</td> <#elseif (item_index+1)%4 ==0>
					<td>${item.name}<input type="checkbox" name="privilegeStr"
						value="${item.acl}" />&nbsp;
				</tr>
				<#else>
				<td>${item.name}<input type="checkbox" name="privilegeStr"
					value="${item.acl}" />&nbsp; </#if> </#list> <#if
					privilegeList?size%4!=0>
				</tr>
				</#if>
				<tr>
					<td><#include "common/form_submit_button.html"/></td>
				</tr>
			</table>

		</form>
</body>
</html>